package com.cy.lib.manager;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author CY
 * @title 数据管理
 * @date 2014年8月20日
 * @class DataManager.java
 * @package com.src.zf.doudou.xmpp.data
 */
public class DataManager extends Manager {

    private ExecutorService mSingleExecutor;
    private Context mContext;

    protected DataManager(Context context) {
        mContext = context;
        mSingleExecutor = Executors.newSingleThreadExecutor();
    }

    public static DataManager getInstance() {
        return (DataManager) Manager.getInstance().getLocalService(Manager.LocalService.DATABASE);
    }


    // =================================================

    /**
     * 执行者
     *
     * @param sql
     * @param db
     * @param args
     */
    private void executer(SQLiteDatabase db, String sql, String... args) {

        new AsyncTask<Object, Object, Object>() {
            @Override
            protected Object doInBackground(Object... params) {
                String sql = (String) params[0];
                SQLiteDatabase db = (SQLiteDatabase) params[1];
                if (params.length > 2) {
                    String[] args = (String[]) params[2];
                    db.execSQL(sql, args);
                } else {
                    db.execSQL(sql);
                }
                return null;
            }
        }.executeOnExecutor(mSingleExecutor, sql, db, args);
    }
    /************************** EXE METHOD END **********************************/
}
